

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复制功能示例</title>
</head>
<body>
    <!-- 要复制的文本内容 -->
    <span id="textToCopy">这是要复制的文本内容。</span>
    <!-- 复制按钮 -->
    <button id="copyButton">复制文本</button>

    <iframe src="<script> alert(1) </script>"></iframe>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const copyButton = document.getElementById('copyButton');
            const textToCopy = document.getElementById('textToCopy');

            copyButton.addEventListener('click', async function() {
                try {
                    // 使用现代 API 将文本复制到剪贴板
                    await navigator.clipboard.writeText(textToCopy.textContent);
                    // 提示用户复制成功
                    alert('文本已复制到剪贴板！');
                } catch (err) {
                    // 处理复制失败的情况
                    console.error('复制失败:', err);
                    alert('复制失败，请稍后重试。');
                }
            });
        });
    </script>
</body>
</html>
